package io.snow.mybatis.crud.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.snow.mybatis.crud.entity.User;
import io.snow.mybatis.crud.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value =  "/")
public class UserController {

    private static final Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "test")
    public String test(){
        // samuelchoi add 3
        User user = new User();
        user.setEmail("samuelchoi@163.com");
        user.setAge(18);
        user.setName("papapa");

        userService.save(user);
        List<User> list = userService.list(new LambdaQueryWrapper<>(new User()).select(User::getId,User::getName));
        list.forEach( u -> LOGGER.info("current user {} ", u));
        return user.getId().toString();
    }
}
